package com.myhome.controller;

import com.myhome.config.constant.R;
import com.myhome.domain.RolePrivilegesParam;
import com.myhome.domain.SysMenu;
import com.myhome.service.SysMenuService;
import com.myhome.service.SysRolePrivilegeService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @Author QYiXin
 * @Date 2021 10 11 09 12
 **/
@RestController
@Api(tags = "用户权限")
public class SysRolePrivilegesController {
    @Autowired
    SysMenuService sysMenuService;
    @Autowired
    SysRolePrivilegeService sysRolePrivilegeService;
    @GetMapping("/roles_privileges")
    public R<List<SysMenu>> getRolePrivileges(Long roleId){
        List<SysMenu> menus = sysMenuService.getRolePrivileges(roleId);
        return R.ok(menus);
    }
    @PostMapping("/grant_privileges")
    @ApiOperation("新增角色权限")
    public R addRolePrivileges(@RequestBody RolePrivilegesParam rolePrivilegesParam){
        boolean isAdd = sysRolePrivilegeService.addPrivileges(rolePrivilegesParam);
        if (isAdd) {
            return R.ok("授权成功");
        }
        return R.fail("授权失败");
    }
}
